Script EntryScript
U4 ret;
String v;
PrintLn("QS Version ", QS_Version());
LibLoad(LinWin("./libQHTTP.so", "QHTTP.dll"), "QHTTP", ret);
if (ret)
{
	PrintLn("Failed to LibLoad, ", ret);
	return;
}

Version@QHTTP(v);
PrintLn("QHTTP lib is ", v);

EndScript

Script Start
(x, port)

U4 ret;

GCreateEx2(x, "HTTPServer", "QHTTP");

ConfigureHttpServer@QHTTP(:x, "Name", x, ret);				//Name should be object name used in GCreateEx2 for the HTTPServer
ConfigureHttpServer@QHTTP(:x, "LocalIP", "0.0.0.0", ret);
ConfigureHttpServer@QHTTP(:x, "LocalPort", port, ret);
ConfigureHttpServer@QHTTP(:x, "LogFileName", "Log/QHTTP.txt", ret);
ConfigureHttpServer@QHTTP(:x, "TimeFormat", "%T ", ret);
ConfigureHttpServer@QHTTP(:x, "Handler", "Handler", ret);

StartHttpServer@QHTTP(:x, ret);
PrintLn(ret);
EndScript

Script Stop
U4 ret;
StopHttpServer@QHTTP(:X, ret);
PrintLn(ret);
EndScript


Script Handler
(type, name, id, startline, header, body)
(type, ip, port)
(type, name, id)

U4 ret;
String resLine;
IMap resHeader;
String resBody;

switch (type)
{
case 0
	PrintLn("Socket is bind to ", ip, ":", port);
	break;
	
case 1
	PrintLn("HTTP request is received");
	PrintLn(startline);
	PrintLn(header);
	PrintLn(body);
	
	resLine = "HTTP/1.1 200 OK";
	IMapPush(resHeader, "Test1", "Value1");
	IMapPush(resHeader, "Test2", "Value2");
	resBody = '{"A" : "Apple", "B" : "Ball"}';
	
	SendHttpMessage@QHTTP(:name, id, resLine, resHeader, resBody, 1, ret);
	break;
	
case 2
	PrintLn("Socket ", id, " is disconnected");
	break;
	
}
EndScript




